package com.aya.aop.asp;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Aspect
public class FirstAnnotationAspect {
    Logger logger = LoggerFactory.getLogger(FirstAnnotationAspect.class);

    @Pointcut("@annotation(com.aya.aop.asp.AopAnnotation)")
    public void pointCutA() {
    }

    @Before("pointCutA()")
    public void before() throws Throwable {
        logger.info("FirstAnnotationAop:before");
    }

    @Pointcut("@annotation(aopAnnotation)")
    public void pointCutB(AopAnnotation aopAnnotation) {
    }

    @Pointcut("execution(public * com.aya..*(..))")
    public void execPackage() {
    }

    @AfterReturning("execPackage() && pointCutB(aopAnnotation)")
    public void afterReturning(AopAnnotation aopAnnotation) throws Throwable {
        logger.info("FirstAnnotationAop:afterReturning");
    }

    @Around("@annotation(aopAnnotation)")
    public Object doAround(ProceedingJoinPoint pjp, AopAnnotation aopAnnotation)
            throws Throwable {
        logger.info("FirstAnnotationAop:start");
        Object obj = pjp.proceed();
        logger.info("FirstAnnotationAop:end");
        return obj;
    }
}
